<?php
switch($action) {
case listModule;
	listModule();
	break;
case add;
	add();
	break;
case edit;
	edit();
	break;
case delete;
	delete();
	break;
case orders;
	orders();
	break;
}


/*模块列表*/
function listModule() {
	global $config,$userInfo;
	$Role = new Role();
	$module = $Role->roleTreeSort();
	include template('manage/listModule');
}

/*添加模块*/
function add() {
	global $config,$userInfo;
	if(_g('submit')) {
		$data['text'] = trim(_g('module_name'));
		if(!$data['text']) {
			$message = array(
				'status' => 'error',
				'msg' => '模块名称未填写',
			);
			echo json_encode($message);
			exit;
		}
		$module = new Role();
		$data['pid'] = max(0,_g('pid'));
		$pModule = $module->lookRoleModule(_g('pid'));
		$data['mid'] = rand_string();
		$data['ptext'] = $pModule['text'];
		$data['binid'] = max(0,_g('binid'));
		$bModule = $module->lookRoleModule(_g('binid'));
		$data['btext'] = $bModule['text'];
		$data['file'] = trim(_g('fileName'));
		$data['action'] = trim(_g('actionName'));
		$data['icon'] = trim(_g('icon'));
		$data['display'] = trim(_g('display'));
		$data['state'] = trim(_g('state'));
		if(empty($data['display'])) {
			$data['display'] = 'none';
		}
		$id = $module->addRoleModule($data);
		if($id) {
			$message = array(
				'status' => 'OK',
				'msg' => '更新成功',
			);
			echo json_encode($message);
			exit;
		}else{
			$message = array(
				'status' => 'error',
				'msg' => $id,
			);
			echo json_encode($message);
			exit;
		}
	}else{
		include template('manage/addModule');
	}
}

/*编辑模块*/
function edit() {
	global $config,$userInfo;
	if(_g('submit')) {
		$id = intval(_g('id'));
		if(!$id) {
			$message = array(
				'status' => 'error',
				'msg' => '请刷新页面数据未知错误',
			);
			echo json_encode($message);
			exit;
		}
		$data['text'] = trim(_g('module_name'));
		if(!$data['text']) {
			$message = array(
				'status' => 'error',
				'msg' => '请刷新页面数据未知错误',
			);
			echo json_encode($message);
			exit;
		}
		$module = new Role();
		$data['pid'] = max(0,_g('pid'));
		$pModule = $module->lookRoleModule(_g('pid'));
		$data['ptext'] = $pModule['text'];
		$data['binid'] = max(0,_g('binid'));
		$bModule = $module->lookRoleModule(_g('binid'));
		$data['btext'] = $bModule['text'];
		$data['file'] = trim(_g('fileName'));
		$data['action'] = trim(_g('actionName'));
		$data['icon'] = trim(_g('icon'));
		$data['display'] = trim(_g('display'));
		$data['state'] = trim(_g('state'));
		if(empty($data['display'])) {
			$data['display'] = 'none';
		}
		$module->editSaveModule($data,$id);
		$message = array(
			'status' => 'OK',
			'msg' => '更新成功',
		);
		echo json_encode($message);
		exit;
	}else{
		$id = intval(_g('module_id'));
		$Role = new Role();
		$module = $Role->lookRoleModule($id);
		include template('manage/editModule');
	}
}

/*删除模块*/
function delete() {
	global $config,$userInfo;
	$id = intval(_g('module_id'));
	$Role = new Role();
	$module = $Role->DelteModule($id);
	$message = array(
		'status' => 'success',
		'msg' => '删除成功',
	);
	echo json_encode($message);
	exit;
}

/*模块排序*/
function orders() {
	global $config,$userInfo;
	$id = intval(_g('id'));
	$value = intval(_g('orders'));
	$Role = new Role();
	$Role->taxisModulegory($value,$id);
	$message = array(
		'status' => 'success',
		'value' => $value,
	);
	echo json_encode($message);
	exit;
}

?>